package me.jiatao.paging3.network

import android.app.Application
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.async
import me.jiatao.paging3.network.pojo.ProjectPage
import me.jiatao.paging3.network.retrofit.RetrofitClient
import me.jiatao.paging3.network.viewmodel.HttpViewModel

/**
 * 用于演示在ViewModel请求网络接口
 */
class ProjectHttpViewModel(application: Application) : HttpViewModel(application) {

    val projectPageLiveData = MutableLiveData<ProjectPage>()

    init {
        viewModelScope.async {
            val projectPage = execHttpResponse {
                RetrofitClient.wanAndroidApi.getProjectList(0)
            }

            projectPageLiveData.postValue(projectPage)
        }
    }
}